<template>
  <div class="AddCard_container">
    <div class="banner"></div>
    <div class="navbar">
      <div class="left" @click="$router.go(-1)"><van-icon name="arrow-left" /></div>
      <div class="center">办理卡片</div>
      <div class="left"><van-icon style="opacity: 0;" name="arrow-left" /></div>
    </div>

    <div class="card">
      <div class="item">
        <div class="label">卡片类型</div>
        <input type="text" v-model="name" class="input" placeholder="请输入卡片类型">
      </div>
      <div class="item">
        <div class="label">充值金额</div>
        <input type="text" v-model="price" class="input" placeholder="请输入充值金额">
      </div>
      <div class="item">
        <div class="label">有效期</div>
        <input type="text" v-model="time" class="input" placeholder="请输入有效期">
      </div>
      <div class="button" @click="submit">
        <van-icon name="add" /><span>确认办理</span>
      </div>
    </div>
  </div>
</template>

<script>
import { addCard } from '@/api'
import { Toast } from 'vant'
export default {
  name: 'AddCard',
  components: {},
  props: {},
  data() {
    return {
      name: '',
      price: '',
      time: ''
    }
  },
  computed: {},
  watch: {},
  created() { },
  mounted() { },
  methods: {
    async submit() {
      if (this.name === '' || this.price === '' || this.time === '') return Toast.fail('请检查以上必填项!')

      try {
        const res = await addCard(
          {
            name: this.name,
            price: this.price,
            shijian: this.time,
            user_id: this.$store.getters.userInfo.id
          }
        )
        if (res.code == 200) {
          this.$router.push({ path: '/card' })
          Toast.success(res.msg)
        } else {
          Toast.fail(res.msg)
        }
      } catch (error) {
        console.log(error);
      }
    }
  }
}
</script>
<style scoped lang='less'>
.AddCard_container {
  height: 100vh;
  overflow: hidden;
  position: relative;
  background-color: #f5f5f5;

  .banner {
    position: relative;
    width: 100%;
    overflow: hidden;
    height: 300px;
  }

  .banner::after {
    height: 300px;
    content: '';
    width: 200%;
    position: absolute;
    left: -50%;
    top: 0;
    border-radius: 0 0 50% 50%;
    background-image: url('../../../assets/image/WechatIMG196.jpg');
    background-size: cover;
  }

  .navbar {
    position: absolute;
    width: calc(100% - 60px);
    top: 20px;
    left: 0;
    padding: 30px;
    display: flex;
    justify-content: space-between;
    color: #fff;
    font-weight: 700;

    .center {
      font-size: 16px;
    }

    .left {
      font-size: 20px;
    }
  }

  .card {
    position: absolute;
    top: 180px;
    left: 50%;
    transform: translateX(-50%);
    padding: 20px 10px;
    width: 80%;
    margin: 0 auto;
    height: 400px;
    background-color: #fff;
    border-radius: 30px;
    box-shadow: 0 10px 10px rgba(0, 0, 0, 0.1);

    /* 添加阴影效果 */

    .item {
      margin-left: 20px;
      margin-top: 10px;
      margin-bottom: 20px;
      color: #7A7A7A;
      padding: 0 30px 0 0;

      .label {
        font-size: 14px;
      }

      .input {
        margin-top: 10px;
        width: 100%;
        height: 50%;
        border: 2px solid #E7E7E7;
        border-radius: 6px;
        font-size: 14px;
        padding: 10px 10px;
      }
    }

    .button {
      text-align: center;
      font-size: 16px;
      color: #438883;
      padding: 10px 0;
      margin: 50px auto 0 auto;
      width: 60%;
      border: 2px solid #438883;
      border-radius: 6px;

      span {
        display: inline-block;
        width: 90px;
      }
    }

  }
}
</style>
